package com.demos.springcloud.provider07HystrixFallback.controller;

import com.demos.springcloud.provider07HystrixFallback.service.FallbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("fallback")
public class controller {

    @Autowired
    private FallbackService fallbackService;

    @PostMapping("data")
    public Map<String, Object> service1(@RequestParam(name="id") String id, HttpServletRequest request){
        System.out.println("07 " + System.currentTimeMillis());

        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("name", "provider07HystrixFallback");
        map.put("m2", fallbackService.method02(id));
        map.put("m1", fallbackService.method01(id));
        map.put("Thread", Thread.currentThread().getName());
        return map;
    }

}
